﻿using CarterWechatServer.BizModel.Dish;
using CarterWechatServer.DataEntity;
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CarterWechatServer.BizLogic.Dish
{
    /// <summary>
    /// 菜品管理服务类
    /// </summary>
    public class DishService
    {

        #region 菜品管理==菜品列表

        public List<DishOutput> Dish()
        {
            using(EFContext db = new EFContext())
            {
                List<DishOutput> outputs = db.DishCategories
                    .Include(m => m.Dishes)
                    .Select(m => new DishOutput()
                    {
                        CategoryId = m.Id,
                        CategoryName = m.CategoryName,
                        Dishes = m.Dishes.Select(s => new DishInfo()
                        {
                            DishId = s.Id,
                            DishName = s.DishName,
                            ImageUrl = s.ImageUrl,
                            UnitPrice = s.UnitPrice,
                            MemberPrice = s.MemberPrice
                        }).ToList()
                    }).ToList();

                //获取推荐的菜品
                List<DishInfo> recommendList = db.Dishes
                       .Select(m => new DishInfo()
                       {
                           DishId = m.Id,
                           DishName = m.DishName,
                           ImageUrl = m.ImageUrl,
                           UnitPrice = m.UnitPrice,
                           MemberPrice = m.MemberPrice
                       }).ToList();

                outputs.Insert(0, new DishOutput()
                {
                    CategoryId = 0,
                    CategoryName = "推荐",
                    Dishes = recommendList
                });

                return outputs;
            }
        }

        #endregion
    }
}
